package com.gs.core.service.impl;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.gs.core.domain.Action;
import com.gs.core.repository.ActionRepository;
import com.gs.core.service.ActionService;

@Service(value="actionService")
@Transactional(propagation=Propagation.SUPPORTS,readOnly=true)
public class ActionServiceImpl implements ActionService{

	@Autowired
	ActionRepository actionRepository;
	
	public List<Action> findAll() {
		long actionCount = actionRepository.count();
		System.out.println("There are " + actionCount + " actions.");
		if(actionCount>0){
			Collection<Action> actions = actionRepository.findAll();
			int counter=1;
			for(Action a:actions){
				System.out.println("Action "+(counter++)+ ". "+a);
			}
		}
		return actionRepository.findAll();
	}


	public Action findById(Long id) {
		return actionRepository.findOne(id);
	}
	@Transactional(propagation=Propagation.REQUIRED,readOnly=false)
	public Action saveOrUpdate(Action entity) {
		return actionRepository.save(entity);
	}
	@Transactional(propagation=Propagation.REQUIRED,readOnly=false)
	public void delete(Action entity) {
		actionRepository.delete(entity);
	}
	@Transactional(propagation=Propagation.REQUIRED,readOnly=false)
	public void deleteAll() {
		actionRepository.deleteAll();
	}

}
